package com.msteam.builder.templates;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import com.msteam.kernel.util.ClassUtils;
import com.msteam.tools.code.generator.template.FileMeta;

public class TemplateVersion {
	// 此文件只是为了FreeMarker插件，添加Context在templates文件上用，不然没有文件夹显示，无法添加Context
	public static void main(String[] args) throws IOException {
		TemplateVersion tv = new TemplateVersion();
		tv.test();

	}
	
	public void test() throws IOException{
		List<Class<FileMeta>> controllerClassList = ClassUtils.scanSubClass(FileMeta.class);
		//System.out.println("classList Size:"+controllerClassList.size());
		if (controllerClassList != null) {
			for (Class<?> clz : controllerClassList) {
				Class<?> clazz = null;
				try {
					clazz =Class.forName(clz.getName());
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				FileMeta fm = null;
				try {
					fm=  (FileMeta) clz.newInstance();
				} catch (InstantiationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				InputStream in = clz.getResourceAsStream(fm.getFileName());
				byte[] buffer = new byte[2048];
		        int readBytes = 0;
		        StringBuilder stringBuilder = new StringBuilder();
		        while((readBytes = in.read(buffer)) > 0){
		            stringBuilder.append(new String(buffer, 0, readBytes));
		        }
				//clz.getResource(name)
				System.out.println(clz.getName()+":"+fm.getFileName());
				System.out.println(stringBuilder.toString());
				/*RouterMapping urlMapping = clazz.getAnnotation(RouterMapping.class);
				//System.out.println(clazz+"==="+(urlMapping==null));
				if (null != urlMapping && StringUtils.isNotBlank(urlMapping.url())) {
					System.out.println(urlMapping.url() + "\t:" + urlMapping.viewPath()+"\t:"+clazz.getName());
					if (StrKit.notBlank(urlMapping.viewPath())) {
						routes.add(urlMapping.url(), (Class<? extends Controller>) clazz, urlMapping.viewPath());
					} else {
						routes.add(urlMapping.url(), (Class<? extends Controller>) clazz);
					}
				}*/
			}
		}
	}
}
